home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / demos / OpenGL / fadeflip / unitsquare.c++ < prev    next >
C/C++ Source or Header  |  1996-11-11  |  5KB  |  180 lines

  1. /*
  2.  * (c) Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * ALL RIGHTS RESERVED
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software for
  6.  * any purpose and without fee is hereby granted, provided that the above
  7.  * copyright notice appear in all copies and that both the copyright notice
  8.  * and this permission notice appear in supporting documentation, and that
  9.  * the name of Silicon Graphics, Inc. not be used in advertising
  10.  * or publicity pertaining to distribution of the software without specific,
  11.  * written prior permission.
  12.  *
  13.  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  14.  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  15.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  16.  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
  17.  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  18.  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  19.  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  20.  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  21.  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
  22.  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  23.  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  24.  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  25.  *
  26.  * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND
  27.  * Use, duplication, or disclosure by the Government is subject to
  28.  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  29.  * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  30.  * clause at DFARS 252.227-7013 and/or in similar or successor
  31.  * clauses in the FAR or the DOD or NASA FAR Supplement.
  32.  * Unpublished-- rights reserved under the copyright laws of the
  33.  * United States.  Contractor/manufacturer is Silicon Graphics,
  34.  * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
  35.  *
  36.  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  37.  */
  38. #include "unitsquare.h"
  39.  
  40. #include <GL/gl.h>
  41.  
  42. static float vertices[][3] = {
  43.   {-1.0, -1.0, 0.0},
  44.   {0.0, -1.0, 0.0},
  45.   {0.0, 0.0, 0.0},
  46.   {-1.0, 0.0, 0.0},
  47.  
  48.   {0.0, -1.0, 0.0},
  49.   {1.0, -1.0, 0.0},
  50.   {1.0, 0.0, 0.0},
  51.   {0.0, 0.0, 0.0},
  52.  
  53.   {-1.0, 0.0, 0.0},
  54.   {0.0, 0.0, 0.0},
  55.   {0.0, 1.0, 0.0},
  56.   {-1.0, 1.0, 0.0},
  57.  
  58.   {0.0, 0.0, 0.0},
  59.   {1.0, 0.0, 0.0},
  60.   {1.0, 1.0, 0.0},
  61.   {0.0, 1.0, 0.0}
  62.  
  63. };
  64.  
  65. static float texcoord[][2] = {
  66.   {0.0, 0.0},
  67.   {0.5, 0.0},
  68.   {0.5, 0.5},
  69.   {0.0, 0.5},
  70.  
  71.   {0.5, 0.0},
  72.   {1.0, 0.0},
  73.   {1.0, 0.5},
  74.   {0.5, 0.5},
  75.  
  76.   {0.0, 0.5},
  77.   {0.5, 0.5},
  78.   {0.5, 1.0},
  79.   {0.0, 1.0},
  80.  
  81.   {0.5, 0.5},
  82.   {1.0, 0.5},
  83.   {1.0, 1.0},
  84.   {0.5, 1.0}
  85. };
  86.  
  87. unitsquare::unitsquare()
  88. {
  89. }
  90.  
  91. void unitsquare::open()
  92. {
  93. }
  94.  
  95. void unitsquare::draw()
  96. {
  97.   glBegin(GL_QUADS);
  98.  
  99.   glTexCoord2fv(texcoord[0]);
  100.   glVertex3fv(vertices[0]);
  101.   glTexCoord2fv(texcoord[1]);
  102.   glVertex3fv(vertices[1]);
  103.   glTexCoord2fv(texcoord[2]);
  104.   glVertex3fv(vertices[2]);
  105.   glTexCoord2fv(texcoord[3]);
  106.   glVertex3fv(vertices[3]); 
  107.  
  108.   glTexCoord2fv(texcoord[4]);
  109.   glVertex3fv(vertices[4]);
  110.   glTexCoord2fv(texcoord[5]);
  111.   glVertex3fv(vertices[5]);
  112.   glTexCoord2fv(texcoord[6]);
  113.   glVertex3fv(vertices[6]);
  114.   glTexCoord2fv(texcoord[7]);
  115.   glVertex3fv(vertices[7]); 
  116.  
  117.   glTexCoord2fv(texcoord[8]);
  118.   glVertex3fv(vertices[8]);
  119.   glTexCoord2fv(texcoord[9]);
  120.   glVertex3fv(vertices[9]);
  121.   glTexCoord2fv(texcoord[10]);
  122.   glVertex3fv(vertices[10]);
  123.   glTexCoord2fv(texcoord[11]);
  124.   glVertex3fv(vertices[11]); 
  125.  
  126.   glTexCoord2fv(texcoord[12]);
  127.   glVertex3fv(vertices[12]);
  128.   glTexCoord2fv(texcoord[13]);
  129.   glVertex3fv(vertices[13]);
  130.   glTexCoord2fv(texcoord[14]);
  131.   glVertex3fv(vertices[14]);
  132.   glTexCoord2fv(texcoord[15]);
  133.   glVertex3fv(vertices[15]); 
  134.  
  135.   glEnd();
  136. }
  137.  
  138. void unitsquare::draw_backwards()
  139. {
  140.   glBegin(GL_QUADS);
  141.  
  142.   glTexCoord2fv(texcoord[3]);
  143.   glVertex3fv(vertices[3]);
  144.   glTexCoord2fv(texcoord[2]);
  145.   glVertex3fv(vertices[2]);
  146.   glTexCoord2fv(texcoord[1]);
  147.   glVertex3fv(vertices[1]);
  148.   glTexCoord2fv(texcoord[0]);
  149.   glVertex3fv(vertices[0]); 
  150.  
  151.   glTexCoord2fv(texcoord[7]);
  152.   glVertex3fv(vertices[7]);
  153.   glTexCoord2fv(texcoord[6]);
  154.   glVertex3fv(vertices[6]);
  155.   glTexCoord2fv(texcoord[5]);
  156.   glVertex3fv(vertices[5]);
  157.   glTexCoord2fv(texcoord[4]);
  158.   glVertex3fv(vertices[4]); 
  159.  
  160.   glTexCoord2fv(texcoord[11]);
  161.   glVertex3fv(vertices[11]);
  162.   glTexCoord2fv(texcoord[10]);
  163.   glVertex3fv(vertices[10]);
  164.   glTexCoord2fv(texcoord[9]);
  165.   glVertex3fv(vertices[9]);
  166.   glTexCoord2fv(texcoord[8]);
  167.   glVertex3fv(vertices[8]); 
  168.  
  169.   glTexCoord2fv(texcoord[15]);
  170.   glVertex3fv(vertices[15]);
  171.   glTexCoord2fv(texcoord[14]);
  172.   glVertex3fv(vertices[14]);
  173.   glTexCoord2fv(texcoord[13]);
  174.   glVertex3fv(vertices[13]);
  175.   glTexCoord2fv(texcoord[12]);
  176.   glVertex3fv(vertices[12]); 
  177.  
  178.   glEnd();
  179. }
  180.